<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'待分售后用户列表'),
);
$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['workers']=$this->getall('worker',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
$storeids=$this->getall('store',array('uniacid'=>$_SESSION['uniacid'],'jiaoxueid'=>$_SESSION['storeid']),array('id','title'),'id');
if($storeids){
	$storeids=array_keys($storeids);
}else{
	$storeids=-1;
}
$batch=array(array('type'=>'modal','url'=>'/jiaoxue.member/worker11id/','title'=>'一键分配售后群'));
//客户列表
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('storeid'=>$storeids,'uniacid'=>$_SESSION['uniacid'],'status'=>36);
	if($_RQ['jibie_type'] && $_RQ['jibie_type']!='all'){
		$params['jibie_type']=intval($_RQ['jibie_type']);
	}
	$return['params']['jibie_type']=$_RQ['jibie_type']?:'all';
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','del_message'=>'确认删除该客户吗？','total'=>$total,'psize'=>$psize,'del_op'=>'del','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'storeid','title'=>'所属门店','type'=>'select','options'=>'stores'),
			array('name'=>'jibie_type','title'=>'客户级别','type'=>'radio','options'=>'jibie_type'),
			array('name'=>'from_type','title'=>'渠道','type'=>'radio','options'=>'from_type'),
			array('name'=>'from1_type','title'=>'实体来源','type'=>'radio','options'=>'from1_type'),
			array('name'=>'from12_type','title'=>'网络来源','type'=>'radio','options'=>'from12_type'),
			array('name'=>'worker3id','title'=>'网络专员','type'=>'select','options'=>'workers'),
			array('name'=>'worker4id','title'=>'前台员','type'=>'select','options'=>'workers'),
			array('name'=>'worker5id','title'=>'电客员','type'=>'select','options'=>'workers'),
			array('name'=>'worker6id','title'=>'销售员员','type'=>'select','options'=>'workers'),
			array('name'=>'worker7id','title'=>'体验员','type'=>'select','options'=>'workers'),
			array('name'=>'worker8id','title'=>'试用员','type'=>'select','options'=>'workers'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'添加日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','action'=>'jy_yxw/jiaoxue.member/worker11id','title'=>'分配售后群'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'客户名称','name'=>'title','help'=>''),
		),
	);
	$return['status']=$this->member_status;
	$return['status']['all']='全部';
	$return['jibie_type']=$this->member_jibie_type;
	$return['from_type']=$this->member_from_type;
	$return['from1_type']=$this->member_from1_type;
	$return['from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='worker11id'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if(!$post['classid']){
			exi('请选择售后群！','error');
		}
		$ids=$post['ids'];
		foreach($ids as $id){
			$id=intval($id);
			if($id){
				$post['memberid']=$id;
				$this->model('xuesheng')->addxuesheng($post);
				$class=$this->get('class',array('id'=>$post['classid'],'uniacid'=>$_SESSION['uniacid']));
				pdo_update('jy_yxw_member',array('status'=>11,'worker11id'=>$class['workerid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			}
		}
		exi('操作成功！','','//list/');
	}
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
		$item=pdo_get('jy_yxw_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}
	if(count($ids)==0){
		exi('请先选择客户','error');
	}
	$item['ids']=$ids;
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'分配售后群',
	);
	$htmls['edit']=array(
		array('type'=>'select','title'=>'分配售后群','name'=>'classid','options'=>'class'),
	);
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			$this->model('member')->check_del($id,'xiaoshou');
			pdo_delete('jy_yxw_member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}